home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / SC++ 7.0.2 Update / TCL Demos / Art Class ƒ / Art Class Sources / CAboutBox.cp next >
Encoding:
Text File  |  1994-03-25  |  5.7 KB  |  242 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CAboutBox.c
  3.  
  4.                             The AboutBox Class
  5.         
  6.     SUPERCLASS = CDirector
  7.     
  8.     Copyright © 1989 Symantec Corporation. All rights reserved.
  9.  
  10.     TCL 1.1.3 Changes:
  11.     [
  12.         - A stray deactivate event appeared to be left on the queue after this
  13.           class is disposed; CurDeactive is set to NULL at the end of Dispose.
  14.     ]
  15.     TCL 2.0 Changes:
  16.     [
  17.         - Replaced IAboutBox and Dispose with contructor and destructor.
  18.     ]
  19.  ******************************************************************************/
  20.  
  21. #include "Global.h"
  22. #include "OSChecks.h"
  23. #include "CDesktop.h"
  24. #include "CDecorator.h"
  25. #include "CWindow.h"
  26. #include "CPicture.h"
  27. #include "CAboutBox.h"
  28. #include "CApplication.h"
  29. #include <LoMem.h>
  30.  
  31. /*** Global Variables ***/
  32.  
  33. extern CDesktop        *gDesktop;            /* The visible Desktop                */
  34. extern CDecorator    *gDecorator;        /* Decorator for arranging windows    */
  35.  
  36. /*** Class Constants ***/
  37.  
  38. #define        WIND_ABOUT        2000
  39.  
  40. typedef struct {
  41.     SignedByte    h;
  42.     SignedByte    v;
  43. } BytePoint;
  44.  
  45. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  46.  
  47.  
  48. /******************************************************************************
  49.  IAboutBox
  50.  
  51.         Initialize an AboutBox object
  52.  ******************************************************************************/
  53.  
  54. CAboutBox::CAboutBox(CApplication *itsSupervisor) : CDirector(itsSupervisor)
  55. {
  56.     TRY
  57.     {
  58.         itsWindow = new CWindow(WIND_ABOUT, TRUE, this);      // KI 2/13/94
  59.         
  60.         gDecorator->CenterWindow(itsWindow);
  61.         
  62.         blackboard = GetPicture(2000);        /* Load in resources                */
  63.         flatEraser = GetPicture(2001);
  64.         rightEraser = GetPicture(2002);
  65.         leftEraser = GetPicture(2003);
  66.         wink = GetPicture(2004);
  67.         acHVof = GetResource('HVof', 1);
  68.         ghdHVof = GetResource('HVof', 2);
  69.     
  70.         Display();
  71.     }
  72.     CATCH
  73.     {
  74.         delete this;
  75.     }
  76.     ENDTRY;
  77. }
  78.  
  79.  
  80. /******************************************************************************
  81.  ~AboutBox {OVERRIDE}
  82.  
  83.         Dispose of AboutBox by releasing all its resources
  84.  ******************************************************************************/
  85.  
  86. CAboutBox::~CAboutBox()
  87. {
  88.     TCLForgetResource( blackboard);
  89.     TCLForgetResource( flatEraser);
  90.     TCLForgetResource( rightEraser);
  91.     TCLForgetResource( leftEraser);
  92.     TCLForgetResource( wink);
  93.     TCLForgetResource( acHVof);
  94.     TCLForgetResource( ghdHVof);
  95.     
  96. //    CDirector::~CDirector();    // removed for PowerPC
  97. //    CurDeactive = NULL;        // TCL 1.1.3 3/11/93 MER; stray pending deactivate event
  98. }
  99.  
  100.  
  101. /******************************************************************************
  102.  Display
  103.  
  104.         Display contents of About Box. There's a lot a ugly code here and
  105.         hard-wired values.
  106.  ******************************************************************************/
  107.  
  108.         /*
  109.          * Kill time for the specified duration, in ticks.
  110.          *   Exit early if the mouse is clicked or a key is pressed.
  111.          */
  112.          
  113.         static Boolean        MouseOrKey(
  114.             long        duration)
  115.         {
  116.             long        startTicks;
  117.             KeyMap        macKeyMap;
  118.             
  119.             startTicks = TickCount();
  120.             
  121.             while ((TickCount() - startTicks) < duration) {
  122.                 GetKeys( macKeyMap);
  123.                                 
  124.                 macKeyMap[1] &= 0xFFFFFFFD; /* Mask out Caps Lock */
  125.                 macKeyMap[3] &= 0xFFFFFF7F; /* Mask out Reset key */
  126.                 
  127.                 if ( Button()  ||
  128.                      (macKeyMap[0] != 0)  ||
  129.                      (macKeyMap[1] != 0)  ||
  130.                      (macKeyMap[2] != 0)  ||
  131.                      (macKeyMap[3] != 0) ) {
  132.                         
  133.                     return(TRUE);
  134.                 }
  135.             }
  136.             
  137.             return(FALSE);
  138.         }
  139.             
  140. void    CAboutBox::Display()
  141. {
  142.     Rect                fBlackboard;
  143.     Rect                fFlatEraser;
  144.     Rect                fRightEraser;
  145.     Rect                fLeftEraser;
  146.     Rect                fWink;
  147.     Rect                eraseClip;
  148.     register Rect        *r;
  149.     Rect                theRect;
  150.     register short        i;
  151.     short                n;
  152.     Handle                theHVof;
  153.     register BytePoint    **off;
  154.     RGBColor            chalkColor;
  155.     
  156.     itsWindow->Select();
  157.     itsWindow->Prepare();
  158.     SetOrigin(-12, -12);
  159.     
  160.     fBlackboard = (**blackboard).picFrame;
  161.     fFlatEraser = (**flatEraser).picFrame;
  162.     OffsetRect(&fFlatEraser, 250, 142);
  163.     fRightEraser = (**rightEraser).picFrame;
  164.     fLeftEraser = (**leftEraser).picFrame;
  165.     fWink = (**wink).picFrame;
  166.     OffsetRect(&fWink, 51, 111);
  167.     
  168.     r = &theRect;
  169.     
  170.     DrawPicture(blackboard, &fBlackboard);
  171.     DrawPicture(flatEraser, &fFlatEraser);
  172.     SetRect(&eraseClip, 72, 32, 288, 108);
  173.     
  174.     if (ColorQDIsPresent()) {
  175.         chalkColor.red = 65281;
  176.         chalkColor.green = 65281;
  177.         chalkColor.blue = 52225;
  178.         RGBForeColor(&chalkColor);
  179.         RGBBackColor(&chalkColor);
  180.     } else {
  181.         ForeColor(whiteColor);
  182.     }
  183.  
  184.     while (TRUE) {
  185.         if (MouseOrKey(20L)) return;
  186.         
  187.         SetRect(r, 80, 40, 82, 42);
  188.         n = (short) GetHandleSize(acHVof) / sizeof(BytePoint);
  189.         off = (BytePoint**)(acHVof);
  190.  
  191.         for (i = 0; i < n; i++) {
  192.             OffsetRect(r, (*off)[i].h, (*off)[i].v);
  193.             PaintRect(r);
  194.             if (MouseOrKey(2L)) return;
  195.         }
  196.         
  197.        // Start Erasing "Art Class"
  198.     
  199.         if (MouseOrKey(60L)) return;
  200.         ClipRect(&fFlatEraser);
  201.         DrawPicture(blackboard, &fBlackboard);
  202.         if (MouseOrKey(30L)) return;
  203.         
  204.         ClipRect(&fBlackboard);
  205.         OffsetRect(&fRightEraser, 60 - fRightEraser.left,
  206.                                   12 - fRightEraser.top);
  207.         DrawPicture(rightEraser, &fRightEraser);
  208.         
  209.         for (i = 0; i < 65; i++) {
  210.             OffsetRect(&fRightEraser, 3, 1);
  211.             DrawPicture(rightEraser, &fRightEraser);
  212.             if (MouseOrKey(1L)) return;
  213.         }
  214.         
  215.         for (i = 0; i < 9; i++) {
  216.             OffsetRect(&fRightEraser, 0, 3);
  217.             DrawPicture(rightEraser, &fRightEraser);
  218.             if (MouseOrKey(1L)) return;
  219.         }
  220.         
  221.         fLeftEraser = fRightEraser;
  222.         DrawPicture(leftEraser, &fLeftEraser);
  223.         for (i = 0; i < 65; i++) {
  224.             OffsetRect(&fLeftEraser, -3, -1);
  225.             DrawPicture(leftEraser, &fLeftEraser);
  226.             if (MouseOrKey(1L)) return;
  227.         }
  228.         
  229.         ClipRect(&fLeftEraser);
  230.         DrawPicture(blackboard, &fBlackboard);
  231.         if (MouseOrKey(30L)) return;
  232.         ClipRect(&fBlackboard);
  233.         DrawPicture(flatEraser, &fFlatEraser);
  234.         if (MouseOrKey(30L)) return;
  235.         
  236.         n = (short) GetHandleSize(ghdHVof) / sizeof(BytePoint);
  237.         off = (BytePoint**)(ghdHVof);
  238.         
  239.         // End erasing "Art Class"
  240.     }
  241. }
  242.